import pandas as pd
from PySide2.QtUiTools import QUiLoader
from PySide2.QtWidgets import QApplication

from news_context_factory import NewsExtractorFactory


class NewsClient:
    def __init__(self):
        self.a = 0
        self.b = 0
        self.c = 0
        self.status = 'start'
        self.ui = QUiLoader().load('ui/main.ui')
        self.getData()

        self.ui.start_button.clicked.connect(self.handleStart)
        self.ui.stop_button.clicked.connect(self.handleStop)
        self.ui.checkBox_1.clicked.connect(self.handleCheckBox_1)
        self.ui.checkBox_2.clicked.connect(self.handleCheckBox_2)
        self.ui.checkBox_3.clicked.connect(self.handleCheckBox_3)

    def getData(self):
        data = pd.read_csv("ui/conf.csv")
        self.ui.plainTextEdit.setPlainText(data.to_string())

    def handleStart(self):
        self.extract_news()

    def handleStop(self):
        print("B")

    def handleCheckBox_1(self):
        print("C")

    def handleCheckBox_2(self):
        print("C")

    def handleCheckBox_3(self):
        print("C")

    def extract_news(self):
        factory = NewsExtractorFactory()
        if self.a == 1:
            product_a = factory.create_extractor("A")
            product_a.extract_news()
            print(product_a.news)

        if self.b == 1:
            product_b = factory.create_extractor("B")
            product_b.extract_news()
            print(product_b.news)

        if self.c == 1:
            product_c = factory.create_extractor("C")
            product_c.extract_news()
            print(product_c.news)


app = QApplication([])
client = NewsClient()
client.ui.show()
app.exec_()
